<template>
    <view class="message p40">
        <view class="header">
            <h1 class="title">监测预警统计</h1>
        </view>
        <view class="precipitation-data cards">
            <view class="mon-box">
                <view
                    v-for="(item, index) in monData"
                    :key="index"
                    :id="`mon-${index}`"
                    class="li-mon df"
                    @click="toWarningIntro(item)"
                >
                    <image :src="item.src"></image>
                    <view class="li-box df ac js fdc">
                        <view class="li-name">{{ item.name }}</view>
                        <!-- <view class="li-name">预警数: <text class="li-num">{{item.num}}</text></view> -->
                        <view class="li-name">
                            当日数:
                            <text class="li-num">{{ item.day }}</text>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <!-- 顶部标题栏 -->
        <view class="header">
            <h1 class="title">地质灾害短临预警</h1>
            <div class="time">
                发布时间：{{ dayjs().format('YYYY-MM-DD 20:00:00') }}
            </div>
        </view>

        <!-- 预测与预警区域 -->
        <view class="prediction-warning cards">
            <h2>⚠灾害预测与预警</h2>
            <div class="warning-content">
                <ul>
                    <li v-for="(item, index) in warnList" :key="index">
                        <p>{{ item.qxda06a060 }}</p>
                    </li>
                </ul>
            </div>
        </view>
        <!-- 底部警示条 -->
        <div class="alert-bar" v-if="warnList.length > 0">
            ⚠️ 本预警信息为短临预警，请密切关注实时动态
        </div>
        <div class="alert-bar" v-else>暂无预警</div>
    </view>
</template>

<script setup lang="ts">
import { GetEarlywarningCount_API, GetQxcxQuery_API } from '@/server/mapdzfz'
import { useUserStore } from '@/stores'
import dayjs from 'dayjs'
const store = useUserStore()
const { userInfo } = storeToRefs(store)

const monData = ref([
    {
        src: '/static/img/home/mon-red.png',
        num: '0',
        day: '0',
        name: '红色预警',
        type: '1',
    },
    {
        src: '/static/img/home/mon-origin.png',
        num: '0',
        day: '0',
        name: '橙色预警',
        type: '2',
    },
    {
        src: '/static/img/home/mon-yellow.png',
        num: '0',
        day: '0',
        name: '黄色预警',
        type: '3',
    },
    {
        src: '/static/img/home/mon-blue.png',
        num: '0',
        day: '0',
        name: '蓝色预警',
        type: '4',
    },
])
const getTj = async () => {
    const res = await GetEarlywarningCount_API()
    if (res.code == 0) {
        monData.value[0].name = res.data[0].level
        monData.value[0].num = res.data[0].statisticscount
        monData.value[0].day = res.data[0].nowdaycount

        monData.value[1].name = res.data[1].level
        monData.value[1].num = res.data[1].statisticscount
        monData.value[1].day = res.data[1].nowdaycount

        monData.value[2].name = res.data[2].level
        monData.value[2].num = res.data[2].statisticscount
        monData.value[2].day = res.data[2].nowdaycount

        monData.value[3].name = res.data[3].level
        monData.value[3].num = res.data[3].statisticscount
        monData.value[3].day = res.data[3].nowdaycount
    }
}
const toWarningIntro = (val) => {
    uni.navigateTo({
        url: '/pages/home/warningIntro?type=' + val.type,
    })
}

const warnList = ref([])
const getRiskWarning = async () => {
    const res = await GetQxcxQuery_API({
        publishObject: userInfo.value.AdminName,
        warningTime: dayjs().format('YYYY-MM-DD 20:00:00'),
    })
    if (res.status) {
        warnList.value = res.data
    }
}
onLoad(() => {
    getTj()
    getRiskWarning()
})
</script>

<style lang="scss" scoped>
.message {
    font-family: '微软雅黑', sans-serif;
    background-color: #f8f9fa;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    margin: 20px auto;

    .header {
        margin-bottom: 40rpx;
        padding-bottom: 30rpx;
        border-bottom: 2px solid #007bff;

        .title {
            color: #0056b3;
            font-size: 50rpx;
            font-weight: bold;
        }
    }

    .precipitation-data,
    .prediction-warning {
        background-color: white;
        margin-bottom: 20px;
    }

    .mon-box {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 20rpx;

        .li-mon {
            padding: 20rpx;
            border-radius: 5rpx;

            .li-box {
                margin-left: 30rpx;
                color: #ffffff;

                .li-num {
                    line-height: 40rpx;
                    font-size: 32rpx;
                    font-weight: bold;
                }

                .li-name {
                    line-height: 40rpx;
                    font-size: 28rpx;
                }
            }

            image {
                height: 45rpx;
                width: 40rpx;
            }
        }
    }

    #mon-0 {
        background-color: #f46d63;
    }

    #mon-1 {
        background-color: #f19149;
    }

    #mon-2 {
        background-color: #f6c359;
    }

    #mon-3 {
        background-color: #37a5f9;
    }

    .time {
        color: #6c757d;
        font-size: 0.9em;
    }

    .warning-content {
        margin-top: 30rpx;
        padding-left: 40rpx;
        line-height: 1.6;
        li {
            margin: 16rpx 0;
            list-style: disc;
        }
    }
    .alert-bar {
        padding: 30rpx;
        background-color: #fff3cd;
        border-radius: 12rpx;
        color: #856404;
        font-weight: 500;
        text-align: center;
    }
}
</style>
